package dao;

import java.util.LinkedList;
import java.util.List;

import relations.Associate;
import relations.belongsTo;
import relations.handle;
import relations.PaidWith;
import relations.Returns;
import entities.Media_Company;
import entities.Product;
import entities.Album;
import entities.Order;
import entities.User;

public class ReturnsDAO {

	private static final ReturnsDAO instance = new ReturnsDAO();
	private List<Returns> returnsList;
	//private List<Media_Company>AssociateMediaComp;
	
	private ReturnsDAO(){
		returnsList = new LinkedList<Returns>();
	
		Returns cus = null;
		
		//cus = Associate.newInstance("jaime", "Jaime", "Vazquez", "ja@j.com", 1L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		//belongsTos.add(cus);
		//cus = belongsTo.newInstance("jaime1", "Jaime", "Vazquez", "ja@j.com", 2L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		//belongsTos.add(cus);
	}
	
	public static ReturnsDAO getInstance() {
		return instance;
	}

	public synchronized Returns findReturns(String orderID, Long product_id, int qty, String dateDay, String dateMonth, String dateYear) {
		Returns result = null;
	
		for (Returns s : returnsList){
			if (s.getOrderID().equals(orderID) && s.getProduct_id().equals(product_id) && s.getQty() == qty && s.getDateDay().equals(dateDay) && s.getDateMonth().equals(dateYear) ){
				result = s;
			
			}
		}
		
	
		return result;
	}

	public synchronized void addReturns(Returns obj) throws RecordDuplicateException{
		if (findReturns(obj.getOrderID(), obj.getProduct_id(), obj.getQty(), obj.getDateDay(), obj.getDateMonth(), obj.getDateYear()) != null){
			throw new RecordDuplicateException("Relation Returns with Order ID: " + obj.getOrderID() + " and" + " Product ID: " + obj.getProduct_id() + " is already in the db.");
		}
		else {
			returnsList.add(obj);
			
		}
	}

}
